﻿using System.Data.SqlClient;

namespace BLL.Services.Ratings
{
    public class RatingService : IRatingService
    {
        private readonly RatingCollection _ratingCollection;

        public RatingService(RatingCollection ratingCollection)
        {
            _ratingCollection = ratingCollection;
        }

        public void SetRating(Rating rating)
        {
            try
            {
                _ratingCollection.SetRating(rating);
            }
            catch (SqlException sqlException)
            {
                throw new ServiceException(sqlException.Message);
            }
        }

        public BookRating GetBookRating(int bookId, int userId = 0)
        {
            try
            {
                return _ratingCollection.GetBookRating(bookId, userId);
            }
            catch (SqlException sqlException)
            {
                throw new ServiceException(sqlException.Message);
            }
        }
    }
}
